package com.ftg.shopping.sp_roleinfo.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.sp_roleinfo.entity.SpRoleinfo;
import com.ftg.shopping.sp_roleinfo.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(description = "角色管理")
@RestController
@RequestMapping("/api/sp_roleinfo")
public class RoleController {

    @Autowired
    RoleService roleService;

    @ApiOperation("查看角色全部数据")
    @GetMapping("/list")
    public List<SpRoleinfo> list(){
        return roleService.list();
    }

    @ApiOperation("按主键查看一个角色")
    @PutMapping("/findone/{roleid}")
    public SpRoleinfo list(@ApiParam("主键")@PathVariable int roleid){
        return roleService.findone(roleid);
    }

    @ApiOperation("添加一个角色")
    @PostMapping("/insert")
    public  int insertrole(@RequestBody SpRoleinfo r){
        return roleService.insertrole(r);
    }

    @ApiOperation("更改一个角色")
    @PostMapping("/update")
    public  int updaterole(@RequestBody SpRoleinfo r){
        return  roleService.updaterole(r);
    }

    @ApiOperation("删除一个角色")
    @DeleteMapping("/delete/{roleid}")
    public  int deleterole(@ApiParam("主键")@PathVariable int roleid){
        return roleService.deleterole(roleid);
    }

    @ApiOperation("删除多个角色")
    @DeleteMapping("/delete/{ids}")
    public  int deleteroleIds(@PathVariable List<Integer> ids){
        return roleService.deleteroleIds(ids);
    }

    @ApiOperation("分页查询无模糊")
    @GetMapping("/page")
    public IPage<SpRoleinfo> list(@RequestParam int page, @RequestParam int limit){
        return roleService.testPage(page,limit);
    }

    @ApiOperation("分页查询带模糊")
    @GetMapping("/page1")
    public LayuiPage<SpRoleinfo> list1(@RequestParam int page, @RequestParam int limit, @RequestParam(required = false) String goodsname){
        return roleService.testPage1(page,limit,goodsname);
    }

    @ApiOperation("layui分页")
    @GetMapping("/page2")
    public LayuiPage<SpRoleinfo> page2(@RequestParam int page, @RequestParam int limit){
        return roleService.testPage2(page,limit);
    }


    @ApiOperation("权限二")
    @GetMapping("/quanxian2")
    public Map<String,Object> quanxian2(int roleId){
        return roleService.quanxian2(roleId);
    }

    @ApiOperation("权限三")
    @GetMapping("/quanxian3/{pids}")
    public int quanxian3(int roleId,@PathVariable List<Integer> pids){

        return roleService.quanxian3(roleId,pids);
    }
}
